﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using Infrastructure;
using MSIACCSL2.Web.WarehouseServices;

namespace MSIACCSL2.Web.ReportPage
{
    public partial class CashIn : System.Web.UI.Page
    {
        private DataAccess<Object> DA;
        private ReportDocument reportDocument;
        private string Tipe;

        public CashIn()
        {
            DA = new DataAccess<object>();
            reportDocument = new ReportDocument();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
                LoadReport(Request.QueryString["no"].ToString());
        }
      
    
        protected void Button1_Click(object sender, EventArgs e)
        {
          LoadReport(Request.QueryString["no"].ToString());
        }

  


        public void LoadReport(string noPS)
        {
                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT cbi.NoVoucher,cbi.Tanggal,cbi.AccountNumber AS AccountCashBank ");
                sb.Append(",cbi.[Description],c.AccountName, ");
                sb.Append("cbid.Debit,cbid.Kredit,cbid.AccountNumber AS AccountLawan,");
                sb.Append("cc.AccountName AS AccountNameLawan,cbid.CodeDepartemen,cbid.SINo,cbid.[DESCRIPTION]");
                sb.Append("FROM  CashBankIn cbi ");
                sb.Append("INNER JOIN CashBankInDetail cbid ON cbi.NoVoucher = cbid.NoVoucher ");
                sb.Append("LEFT JOIN COA c ON cbi.AccountNumber = c.AccountNumber ");
                sb.Append("LEFT JOIN COA cc ON cc.AccountNumber = cbid.AccountNumber ");
                sb.AppendFormat("WHERE cbi.NoVoucher='{0}'", noPS);
        
                string reportPath = Server.MapPath("~/Report/VoucherKasMasuk.rpt");
                reportDocument.Load(reportPath);
                var Source = DA.GetDataListDataSet(sb.ToString());
                reportDocument.SetDataSource(Source.Tables[0]);
                CrystalReportViewer1.ReportSource = reportDocument;
                
        }

        protected override void OnUnload(EventArgs e)
        {
            base.OnUnload(e);
            this.Unload += Page_Unload;
        }

        void Page_Unload(object sender, EventArgs e)
        {
            reportDocument.Clone();
            reportDocument.Dispose();
        }
    }
}